package com.eslab.osmonitor.providerDB;

import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

import android.location.Location;

public class CWriter{

	  static final SimpleDateFormat TIMESTAMP_FORMAT =
	      new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
	  static {
	    TIMESTAMP_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
	  }

	  private PrintWriter pw = null;
	  private PowerModel powerModel;

	  public void prepare(PowerModel powerModel, OutputStream out) {
	    this.powerModel = powerModel;
	    this.pw = new PrintWriter(out);
	  }

	  public String getExtension() {
	    return "PowerModel";
	  }

	  public void writePowerModel() {
	    if (pw != null) {
	      pw.println("<powermodel>");
	      pw.println("<cpu>");
	      pw.println("<cpu_on>"+ powerModel.cpu_on + "</cpu_on>");
	      pw.println("<cpu_util>"+ powerModel.cpu_util + "</cpu_util>");
	      pw.println("</cpu>");
	      pw.println("<display>");
	      pw.println("<display_on>"+ powerModel.display_on + "</display_on>");
	      pw.println("<brightness_level>"+ powerModel.brightness_level + "</brightness_level>");
	      pw.println("</display>");
	      pw.println("<wifi>");
	      pw.println("<wifi_on>"+ powerModel.wifi_on + "</wifi_on>");
	      pw.println("<wifi_low>"+ powerModel.wifi_low + "</wifi_low>");
	      pw.println("<wifi_high>"+ powerModel.wifi_high + "</wifi_high>");
	      pw.println("<wifi_threshold>"+ powerModel.wifi_threshold + "</wifi_threshold>");
	      pw.println("</wifi>");
	      pw.println("</powermodel>");
	    }
	  }
	  public void close() {
	    if (pw != null) {
	      pw.close();
	      pw = null;
	    }
	  }
	}
